package org.luu.medicare.controller.medicareInfoController;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.luu.medicare.common.Result;
import org.luu.medicare.entity.PageBean;
import org.luu.medicare.entity.TDisease;
import org.luu.medicare.service.DiseaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/disease")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class DiseaseController {
    private final DiseaseService diseaseService;

    @DeleteMapping("/{id}")
    public Result<String> deleteById(@PathVariable Integer id) {
        log.info("病种 deleteById: {}", id);
        return diseaseService.deleteById(id);
    }

    @PostMapping
    public Result<String> save(@RequestBody TDisease disease) {
        log.info("病种 save: {}", disease);
        return diseaseService.save(disease);
    }

    @PutMapping
    public Result<String> update(@RequestBody TDisease disease) {
        log.info("病种 update: {}", disease);
        return diseaseService.update(disease);
    }

    @GetMapping("/{id}")
    public Result<TDisease> findById(@PathVariable Integer id) {
        log.info("病种 findById: {}", id);
        return diseaseService.findById(id);
    }

    @GetMapping
    public Result<PageBean<TDisease>> page(@RequestParam(defaultValue = "1") int page,
                                           @RequestParam(defaultValue = "10") int pageSize,
                                           String name,
                                           String id) {
        log.info("病种 page: {}, {}, {}, {}", page, pageSize, name, id);
        return diseaseService.page(page, pageSize, name, id);
    }
}
